package gdconf

import (
	"server_cluster/common/logger"
)

// 活动任务配置表

const (
	ActivityTaskTypeDaily  = 1
	ActivityTaskTypeWeekly = 2
)

const (
	ActivityTaskFinishCondFinishActivityDungeon = 1  // 完成活动地牢 参数1:活动id
	ActivityTaskFinishCondEquipUpgrade          = 2  // 装备升级
	ActivityTaskFinishCondEquipAffixRemake      = 3  // 装备词条洗练
	ActivityTaskFinishCondDailyTaskPoint        = 4  // 日常活跃点 参数1:活跃点
	ActivityTaskFinishCondGacha                 = 5  // 卡池抽卡 参数1:卡池id
	ActivityTaskFinishCondFinishFight           = 6  // 完成战斗
	ActivityTaskFinishCondLogin                 = 7  // 登录
	ActivityTaskFinishCondHomeGather            = 8  // 家园收获
	ActivityTaskFinishCondAnyDungeon            = 9  // 完成任意副本战斗次数 参数list [活动id]
	ActivityTaskFinishCondHomeAwardItem         = 10 // 积分建筑收获
	ActivityTaskFinishCondEquipCompose          = 11 // 打造装备
	ActivityTaskFinishCondWeaponCompose         = 12 // 打造武器
)

type ActivityTaskConfig struct {
	TaskId          int32    `csv:"ID" gorm:"primary_key;autoIncrement:false"` // 任务id
	Type            int32    `csv:"Type,omitempty"`                            // 任务类型
	FinishCond      IntArray `csv:"FinishCondition,omitempty"`                 // 完成条件
	FinishCount     int32    `csv:"Count,omitempty"`                           // 完成次数
	RewardTaskPoint int32    `csv:"ActiveReward,omitempty"`                    // 奖励活跃点
	NeedOpenStateId int32    `csv:"UnlockCondition,omitempty"`                 // 所需功能开放id
	ItemReward      ItemList `csv:"ItemReward,omitempty"`
}

func (a *ActivityTaskConfig) TableName() string {
	return "config_activity_task"
}

func (g *GameDataConfig) saveActivityTaskConfig() {
	saveTableToDb[ActivityTaskConfig](g.Db, readTable[ActivityTaskConfig](g.CsvPathPrefix+"Active.csv"))
}

func (g *GameDataConfig) loadActivityTaskConfig() {
	g.GameDataMaps.ActivityTaskConfigMap = make(map[int32]*ActivityTaskConfig)
	for _, activityTaskConfig := range loadTableFromDb[ActivityTaskConfig](g.Db) {
		g.GameDataMaps.ActivityTaskConfigMap[activityTaskConfig.TaskId] = activityTaskConfig
	}
	logger.Info("ActivityTaskConfig Count: %v", len(g.GameDataMaps.ActivityTaskConfigMap))
}

func GetActivityTaskConfig(taskId int32) *ActivityTaskConfig {
	value, exist := CONF.GameDataMaps.ActivityTaskConfigMap[taskId]
	if !exist {
		logger.Error("[ConfigNotFound] ActivityTaskConfig, taskId: %v", taskId)
		return nil
	}
	return value
}

func GetActivityTaskConfigMap() map[int32]*ActivityTaskConfig {
	return CONF.GameDataMaps.ActivityTaskConfigMap
}
